<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<?php $box = $this->beginWidget(
    'bootstrap.widgets.TbBox',
    array(
        'title' => 'Home',
        'headerIcon' => 'icon- fa fa-home'
    )
);?>
	
	<div class="row-fluid">
		<div class="span">
			
			<div style="text-align:center;">
			<h1>Welcome to School Management System <i>(<?php echo CHtml::encode(Yii::app()->name); ?>)</i></h1>
			<img src="<?php echo Yii::app()->request->baseUrl; ?>/images/yiiheart.png" width="200">
			</div>
		</div>

		<div class="span10">
			<?php

			$school = Yii::app()->db->createCommand()
			        ->select('a.institutional_name')
			        ->from('tb_tenant a ')
			        ->queryColumn();

			$total = Yii::app()->db->createCommand()
					->select('count(a.institutional_name)')
					->from('tb_tenant a ')
					->leftjoin('tb_tenant_student b', 'a.id = b.tenant_id')
					//->leftJoin('tb_tenant_student b on a.id = b.tenant_id')
					->group('a.id')
					->queryColumn();
					
			$male = Yii::app()->db->createCommand()
					->select('count(a.institutional_name)')
					->from('tb_tenant a ')
					->leftjoin('tb_tenant_student b', 'a.id = b.tenant_id')
					->leftjoin('tb_student c', 'c.id = b.student_id')
					->where(' c.sex = 1')
					->group('a.id')
					->queryColumn();
		
			$female = Yii::app()->db->createCommand()
					->select('count(a.institutional_name)')
					->from('tb_tenant a ')
					->leftjoin('tb_tenant_student b', 'a.id = b.tenant_id')
					->leftjoin('tb_student c', 'c.id = b.student_id')
					->where(' c.sex = 2')
					->group('a.id')
					->queryColumn();


			foreach ($total as $key => $value) {
				$total[$key] = (float)$value;
			}

			foreach ($male as $key => $value) {
				$male[$key] = (float)$value;
			}

			foreach ($female as $key => $value) {
				$female[$key] = (float)$value;
			}

			$this->widget(
			    'bootstrap.widgets.TbHighCharts',
			    array(
			        'options' => array(
			        	'chart' => array(
			                'type' => 'column', // area, column, bar, pie, scatter
			            ),
			            'title' => array(
			                'text' => 'Student Statistics',
			                'x' => -20 //center
			            ),
			            'subtitle' => array(
			                'text' => 'Source: WorldClimate.com',
			                'x' -20
			            ),
			            'xAxis' => array(
			                'categories' => $school, // array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'),
			            ),
			            'yAxis' => array(
			                'title' => array(
			                    'text' =>  'Student',
			                ),
			                'plotLines' => array(
			                    array(
			                        'value' => 0,
			                        'width' => 1,
			                        'color' => '#808080'
			                    )
			                ),
			            ),
			            'tooltip' => array(
			                'valueSuffix' => ''
			            ),
			            'legend' => array(
			                'layout' => 'vertical',
			                'align' => 'right',
			                'verticalAlign' => 'middle',
			                'borderWidth' => 0
			            ),
			            'series' => array(
			                array(
			                    'name' => 'Total',
			                    'data' => $total,
			                ),
			                array(
			                    'name' => 'Male',
			                    'data' => $male,
			                ),
			                array(
			                    'name' => 'Female',
			                    'data' => $female,
			                )
			            )
			        ),
			        'htmlOptions' => array(
			            'style' => 'min-width: 310px; height: 400px; margin: 0 auto'
			        )
			    )
			);
			?>
		</div>

		<div>
			<?php 
				$this->widget('bootstrap.widgets.TbGridView', array(
				    'type'=>'striped bordered condensed',
				    'dataProvider'=> Tenant::model()->search(),
				    'template'=>"{items}{summary}",
				    'columns'=>array(
				        array(
				        	'header'=>'#',  
				        	'value' => '$row + 1 + ($this->grid->dataProvider->pagination->currentPage
* $this->grid->dataProvider->pagination->pageSize)'),
				        array(
				        	'name' => 'tenant_name',
				       	),
				       	array(
				       		'name' => 'institutional_name',
				       	),
				       	array(
				       		'name' => 'address',
				       	),
				       	array(
				       		'name' => 'registration_date',
				       	),
				       	array(
				       		'name' => 'admin_user',
				       	),
				       	array(
				       		'header' => 'Pasword',
				       		'value' => '"admin"',
				       	)
				    ),
				)); 
			?>
		</div>
	</div>
	
<?php $this->endWidget(); ?>
<div class="clearfix"><hr></div>
